package org.bankabeule.ui.actions;

import org.bankabeule.Model;
import org.bankabeule.core.ModelManager;
import org.bankabeule.ui.Activator;
import org.bankabeule.ui.utils.Logger;
import org.eclipse.jface.action.LegacyActionTools;

/**
 * 
 */
public class SaveAction extends AbstractAction {

    /**
     * Constructor
     */
    public SaveAction() {
        super();
        setText("Save");
		setId(getClass().getCanonicalName());
		setImageDescriptor(Activator.getImageDescriptor("Save.gif"));
		setAccelerator(LegacyActionTools.convertAccelerator("CTRL+S"));
    }

    
    /**
     * Overridden method.
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
    @Override
    public void run() {
        try {
            ModelManager.get().save();
        } catch (Exception e) {
            Logger.log(e);
        }
    }


	@Override
	public void modelLoaded(Model model) {
		setEnabled(false);
	}
	

	@Override
	public void modelDirty(Model model) {
		setEnabled(true);
	}



	@Override
	public void modelSaved(Model model) {
		setEnabled(false);
	}
       

}
